/**
 * 
 */
package com.pavco.caribbeanvisit.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.HTML;
import com.google.inject.Inject;
import com.pavco.caribbeanvisit.client.CaribbeanvisitConstants;

/**
 * @author wikid
 *
 */
public class CountryChooser extends Composite {
  HandlerManager eventBus;

  private static CountryChooserWidgetUiBinder uiBinder = GWT
      .create(CountryChooserWidgetUiBinder.class);

  @UiTemplate("CountryChooserWidget.ui.xml")
  interface CountryChooserWidgetUiBinder extends
      UiBinder<Widget, CountryChooser> {
  }
  
  /**
   * The message displayed to the user when the server cannot be reached or
   * returns an error.
   */
  /*private static final String SERVER_ERROR = "An error occurred while "
      + "attempting to contact the server. Please check your network "
      + "connection and try again.";*/

  @UiField VerticalPanel panel;
  @UiField HTML label;
  @UiField ListBox countryListBox;
  
  private CaribbeanvisitConstants constants = 
      GWT.create(CaribbeanvisitConstants.class);
  
  /**
   * Constructor that initializes this widget
   *
   * @param map The associated {@link PavcoMap} to link with
   */
  @Inject
  public CountryChooser() {
    initWidget(uiBinder.createAndBindUi(this));
    
    label.setHTML(constants.selectCountry() + ":");
  }
  
  public void setCountries(String[] countryNames) {
    for (int i = 0; i < countryNames.length; ++i) {
      countryListBox.addItem(countryNames[i], Integer.toString(i));
    }
  }
  
  public ListBox getListBox() {
    return this.countryListBox;
  }
  
  @UiHandler({"countryListBox"})
  public void onChange(ChangeEvent event) {
    fireEvent(event);
  }  
}